﻿//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbTKB
    {
        private string getthoikhoabieu()
        {
            DataTable tbl = SelectAll();
            String strMess = "";
            String strMess1 = "";

            for (int i = 0; i <= tbl.Rows.Count - 1; i++)
            {
                strMess += tbl.Rows[i][0].ToString().Trim() + tbl.Rows[i][1].ToString().Trim() + tbl.Rows[i][2].ToString().Trim() + tbl.Rows[i][3].ToString().Trim() + tbl.Rows[i][4].ToString().Trim();
                string[] st = tbl.Rows[i][1].ToString().Trim().Split('|');
                string[] st1 = tbl.Rows[i][2].ToString().Trim().Split('|');
                string[] st2 = tbl.Rows[i][3].ToString().Trim().Split('|');
                string[] st3 = tbl.Rows[i][4].ToString().Trim().Split('|');
                strMess1 += tbl.Rows[i][0].ToString().Trim() + "Môn hoc : " + st[0].ToString() + "Tên giáo viên " + st[1].ToString() + "Phòng học" + st[2].ToString() + st1[0].ToString() + "Tên giao viên " + st1[1].ToString() + "Phòng học" + st1[2].ToString() + st2[0].ToString() + "Tên giáo viên " + st2[1].ToString() + "Phòng học" + st2[2].ToString() + st3[0].ToString() + "Tên giao viên " + st3[1].ToString() + "Phòng học" + st3[2].ToString();
            }

            return strMess1;
        }
        public static DataTable TooltipTKB(string Mahv)
        {

            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Mahv", Mahv);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TooltipTKB", pr);
            return all;
        }
        //-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbTKB_SelectAll", null);
            return all;
        }
        public static DataTable SelectAll1()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbTKB_SelectAll1", null);
            return all;
        }
        public static DataTable SelectAll2()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbTKB_SelectAll2", null);
            return all;
        }
        public static DataTable SelectTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbTKB_SelectTop", pr);
            return all;
        }
        //-----------------------------------------------------------//
        public static void Insert(ETbTKB OTbTKB)
        {
            SqlParameter[] pr = new SqlParameter[8];
            pr[0] = new SqlParameter(@"MaTKB", OTbTKB.MaTKB);
            pr[1] = new SqlParameter(@"MaHV", OTbTKB.MaHV);
            pr[2] = new SqlParameter(@"MaMonHoc", OTbTKB.MaMonHoc);
            pr[3] = new SqlParameter(@"MaGV", OTbTKB.MaGV);
            pr[4] = new SqlParameter(@"NgayHoc", OTbTKB.NgayHoc);
            pr[5] = new SqlParameter(@"CaHoc", OTbTKB.CaHoc);
            pr[6] = new SqlParameter(@"PhongHoc", OTbTKB.PhongHoc);
            pr[7] = new SqlParameter(@"MaLop", OTbTKB.MaLop);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbTKB_Insert", pr);
        }
        //-----------------------------------------------------------//
        public static void Update(ETbTKB OTbTKB)
        {
            SqlParameter[] pr = new SqlParameter[8];
            pr[0] = new SqlParameter(@"MaTKB", OTbTKB.MaTKB);
            pr[1] = new SqlParameter(@"MaHV", OTbTKB.MaHV);
            pr[2] = new SqlParameter(@"MaMonHoc", OTbTKB.MaMonHoc);
            pr[3] = new SqlParameter(@"MaGV", OTbTKB.MaGV);
            pr[4] = new SqlParameter(@"NgayHoc", OTbTKB.NgayHoc);
            pr[5] = new SqlParameter(@"CaHoc", OTbTKB.CaHoc);
            pr[6] = new SqlParameter(@"PhongHoc", OTbTKB.PhongHoc);
            pr[7] = new SqlParameter(@"MaLop", OTbTKB.MaLop);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbTKB_Update", pr);
        }
        //-----------------------------------------------------------//
        public static void Delete(int MaTKB)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaTKB", MaTKB);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbTKB_Delete", pr);
        }
        //-----------------------------------------------------------//
        public static ETbTKB SelectByID(int MaTKB)
        {
            ETbTKB OTbTKB = new ETbTKB();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaTKB", MaTKB);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbTKB_SelectByID", pr);
            if (idr.Read())
                OTbTKB = GetOneTbTKB(idr);
            idr.Close();
            idr.Dispose();
            return OTbTKB;
        }
        //-----------------------------------------------------------//
        private static ETbTKB GetOneTbTKB(IDataReader idr)
        {
            ETbTKB OTbTKB = new ETbTKB();
            if (idr["MaTKB"] != DBNull.Value)
                OTbTKB.MaTKB = (int)idr["MaTKB"];
            if (idr["MaHV"] != DBNull.Value)
                OTbTKB.MaHV = (string)idr["MaHV"];
            if (idr["MaMonHoc"] != DBNull.Value)
                OTbTKB.MaMonHoc = (int)idr["MaMonHoc"];
            if (idr["MaGV"] != DBNull.Value)
                OTbTKB.MaGV = (int)idr["MaGV"];
            if (idr["NgayHoc"] != DBNull.Value)
                OTbTKB.NgayHoc = (DateTime)idr["NgayHoc"];
            if (idr["CaHoc"] != DBNull.Value)
                OTbTKB.CaHoc = (string)idr["CaHoc"];
            if (idr["PhongHoc"] != DBNull.Value)
                OTbTKB.PhongHoc = (string)idr["PhongHoc"];
            if (idr["MaLop"] != DBNull.Value)
                OTbTKB.MaLop = (int)idr["MaLop"];
            return OTbTKB;
        }
        //-----------------------------------------------------------//
        public static bool TestByID(int MaTKB)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaTKB", MaTKB);
            pr[1] = new SqlParameter(@"TestID", SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbTKB_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
        //-----------------------------------------------------------//
        public static List<ETbTKB> ListAll()
        {
            List<ETbTKB> list = new List<ETbTKB>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbTKB_SelectAll", null);
            while (idr.Read())
                list.Add(GetOneTbTKB(idr));
            if (idr.IsClosed == false)
            {
                idr.Close();
                idr.Dispose();
            }
            return list;
        }

        public static List<ETbTKB> ListTop(int Top)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"Top", Top);
            List<ETbTKB> list = new List<ETbTKB>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbTKB_SelectAll", pr);
            while (idr.Read())
                list.Add(GetOneTbTKB(idr));
            if (idr.IsClosed == false)
            {
                idr.Close();
                idr.Dispose();
            }
            return list;
        }
    }
 
}